<?php

class IndexAction extends Action {
	
   public function __construct() {
       parent::__construct();
       load("@.dom");
    }
    public function index(){
		$HostInfo =M("Hostinfo");
		$todaytime = strtotime(date("Y-n-d")." 0:0:01" );
		$_HostNodes= $HostInfo
		->field("hostinfo.*,hosts.hostname,hosts.weburl")
		->where("hostinfo.updated > ".$todaytime)
		->join("left join hosts on  hosts.host_id = hostinfo.host_id")
		// ->limit(20)
		// ->page($_GET["page"])
		->order("hostinfo.updated desc")
		->select();
// 		echo $HostInfo->_sql();
		$HostNodes = array();
		foreach ($_HostNodes as $_host){
			
			$content = $_host['content'];
			
			$_host['notag'] = strip_tags($content);			
			$_host['images']=array();
			if ($content!="") {
				$dom = str_get_html($content,"<p>");

				foreach ($dom->find("img") as $img){
					$srcImg =$img->src; 
					if(substr($srcImg,0,4) != "http"){$srcImg=$_host['weburl']."/".$srcImg;}

					$_host['images'][]=$srcImg;
				}
			}
			
			$HostNodes[]=$_host;
		}
		// $HostNodes = $_HostNodes;

		// dump($HostNodes);
		
		$this->assign("HostNodes",$HostNodes);
    	$this->display();
    }
}